package com.mall.service.marketing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.common.CommonPage;
import com.mall.model.domain.SmsFlashPromotion;
import com.mall.service.marketing.mapper.FlashMapper;
import com.mall.service.marketing.service.FlashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName FlashServiceImpl
 * @Description
 * @Author Young
 * @Date 2023/3/12 0:26
 * @Version 1.0
 */
@Service
public class FlashServiceImpl implements FlashService {

    @Autowired
    private FlashMapper flashMapper;

    /**
     * 添加活动
     * @param smsFlashPromotion
     */
    @Override
    public void create(SmsFlashPromotion smsFlashPromotion) {
        flashMapper.insert(smsFlashPromotion);
    }

    /**
     * 删除活动
     * @param id
     */
    @Override
    public void delete(Integer id) {
        flashMapper.deleteById(id);
    }

    /**
     * 根据活动名称分页查询
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public CommonPage list(String keyword, Integer pageNum, Integer pageSize) {
        Page<SmsFlashPromotion> ipage = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsFlashPromotion> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(keyword !=null,SmsFlashPromotion::getTitle,keyword);
        flashMapper.selectPage(ipage,queryWrapper);
        CommonPage page = CommonPage.getPage(ipage);
        return page;
    }

    /**
     * 修改上下线状态
     * @param id
     * @param status
     */
    @Override
    public void updateStatus(Integer id, Integer status) {
        SmsFlashPromotion smsFlashPromotion  = new SmsFlashPromotion();
        smsFlashPromotion.setId(Long.valueOf(id));
        smsFlashPromotion.setStatus(status);
        flashMapper.updateById(smsFlashPromotion);
    }

    /**
     * 编辑活动
     * @param id
     * @param smsFlashPromotion
     */
    @Override
    public void update(Integer id, SmsFlashPromotion smsFlashPromotion) {
        flashMapper.updateById(smsFlashPromotion);
    }

    /**
     * 获取活动详情
     * @param id
     */
    @Override
    public SmsFlashPromotion getFlash(Long id) {
        SmsFlashPromotion smsFlashPromotion = flashMapper.selectById(id);
        return smsFlashPromotion;
    }




}
